
#ifndef __NEW_ACTORS_DB_H
#define __NEW_ACTORS_DB_H

#include <apr_network_io.h>
#include "../aprtools/APRTable.h"
#include "SQLiteDB.h"

class Actor;
class KeyDB;

class ActorsDB : public SQLiteDB
{
   public:
      enum actormarkstype {   ACTORMARK_EXPENDABLE = 'E',
                              ACTORMARK_DATA_COMPLETE = 'C',
                              ACTORMARK_DATA_IS_WORK = 'W',
                              ACTORMARK_DATA_IS_RESULTS = 'R' };
      ActorsDB(const char *filename);
      int testActorExists(const char *actorname);
      char *getUltimateUser(const char *actorname);
      int isEquivalentPermission(const char *user1, const char *user2);
      char *addUser(const char *ihandlename,
                  const char *iparent,
                  int64_t credit,
                  int64_t quota,
                  int64_t lifetime);
      int makeUserPermanent(const char *iname);
      char *addCompute(const char *iparent,
                     int64_t durationseconds,
                     apr_sockaddr_t *cliaddr,
                     const char *capabilities,
                     const char *joblocation);
      int spawnWorkInstances(const char *iinputworkstore,
                             int64_t durationseconds,
                             int iinstances,
                             const char *capabilities);
      int addDataStore(const char *iname,
                       const char *iparent,
                       const char *iorigin,
                       const char *iallhash,
                       const char *idecryptingkeyname,
                       int noofblocks, int64_t blocksize);
      int addDependencyOnKey(const char *iname, const char *ikeyname);
      int addEquivalenceOnKey(const char *iname, const char *ikeyname);
      char *getEquivalentKey(const char *ikeyname);
      APRTable *getActor(const char *iname);
      int removeActorAndKeys(const char *iname, KeyDB *keydb);
      int removeActor(const char *iname);
      int getChildren(std::vector<char *> *children, const char *iname);
      int getExternalAliasesOfChildren(std::vector<char *> *children, const char *iname);
      /** Names of the fields in the 'actors' table. */
      static const char *table_actors_fields_names[];
      /** Names of the fields in the 'users' table. */
      static const char *table_users_fields_names[];
      /** Names of the fields in the 'computes' table. */
      static const char *table_computes_fields_names[];
      /** Names of the fields in the 'workinstances' table. */
      static const char *table_workinstances_fields_names[];
      /** Names of the fields in the 'datastores' table. */
      static const char *table_datastores_fields_names[];
      /** Names of the fields in the 'keydependencies' table. */
      static const char *table_keydependencies_fields_names[];
      /** Names of the fields in the 'keydependencies' table. */
      static const char *table_keyequivalences_fields_names[];
   private:
      /** This class cannot be copied. */
      ActorsDB(const ActorsDB &o);
      /** This class cannot be copied. */
      ActorsDB &operator=(const ActorsDB &o);
      void createTablesIfNecessary();
      int addActor(const char *iname,
                   const char *iclass,
                   const char *iparent,
                   const char *ivalidfrom,
                   const char *iexpireson,
                   const char *iactormark,
                   const char *iexternalalias);
      /** Types of the fields in the 'actors' table. */
      static const char *table_actors_fields_types[];
      /** Types of the fields in the 'users' table. */
      static const char *table_users_fields_types[];
      /** Types of the fields in the 'computes' table. */
      static const char *table_computes_fields_types[];
      /** Types of the fields in the 'workinstances' table. */
      static const char *table_workinstances_fields_types[];
      /** Types of the fields in the 'datastores' table. */
      static const char *table_datastores_fields_types[];
      /** Types of the fields in the 'keydependencies' table. */
      static const char *table_keydependencies_fields_types[];
      /** Types of the fields in the 'keydependencies' table. */
      static const char *table_keyequivalences_fields_types[];
};

#endif
